package com.item.service.Impl;

import com.item.mapper.UserMapper;
import com.item.pojo.Page;
import com.item.pojo.User;
import com.item.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAll() {
        return userMapper.selectAll();
    }

    @Override
    public User selectById(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public Map<String, Object> pageList(Integer pageSize, Integer page, User user) {

        Map<String, Object> map=new HashMap<>();
        Page<User> userPage = new Page<>();

        Integer start=(page-1)*pageSize;

        userPage.setStart(start);
        userPage.setPageSize(pageSize);
        userPage.setData(user);

        // 查询当前页数据
        List<User> userList =  userMapper.pageList(userPage);

        // 查询总记录数
        Integer total =  userMapper.pageCount(user);

        map.put("total",total);

        //System.out.println(userList);
        map.put("obj",userList);

        return map;
    }

    @Override
    public int insert(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int insertBatch(List<User> users) {
        return userMapper.insertBatch(users);
    }

    @Override
    public int delete(Integer id) {
        return userMapper.delete(id);
    }

    @Override
    public int delBatch(List<Integer> id) {
        return userMapper.delBatch(id);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }
}
